[PATCH v2] BLOCK: fix bio.bi_rw handling

Return of the bi_rw tests is no longer bool after commit 74450be1. But
results of such tests are stored in bools. This doesn't fit in there
for some compilers (gcc 4.5 here), so either use !! magic to get real
bools or use ulong where the result is assigned somewhere.

Signed-off-by: Jiri Slaby <jslaby [at] suse.cz>
Cc: Christoph Hellwig <hch [at] lst.de>
Cc: Jens Axboe <axboe [at] kernel.dk>
---
block/blk-core.c | 6 +++---
drivers/block/loop.c | 2 +-
2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/block/blk-core.c b/block/blk-core.c
index 207af0d..29fd2cc 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
[at] [at] -1198,9 +1198,9 [at] [at] static int __make_request(struct request_queue *q, struct bio *bio)
int el_ret;
unsigned int bytes = bio->bi_size;
const unsigned short prio = bio_prio(bio);
- const bool sync = (bio->bi_rw & REQ_SYNC);
- const bool unplug = (bio->bi_rw & REQ_UNPLUG);
- const unsigned int ff = bio->bi_rw & REQ_FAILFAST_MASK;
+ const bool sync = !!(bio->bi_rw & REQ_SYNC);
+ const bool unplug = !!(bio->bi_rw & REQ_UNPLUG);
+ const unsigned long ff = bio->bi_rw & REQ_FAILFAST_MASK;
int rw_flags;

if ((bio->bi_rw & REQ_HARDBARRIER) &&
diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index e647537..0ba2899 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
[at] [at] -476,7 +476,7 [at] [at] static int do_bio_filebacked(struct loop_device *lo, struct bio *bio)
pos = ((loff_t) bio->bi_sector << 9) + lo->lo_offset;

if (bio_rw(bio) == WRITE) {
- bool barrier = (bio->bi_rw & REQ_HARDBARRIER);
+ bool barrier = !!(bio->bi_rw & REQ_HARDBARRIER);
struct file *file = lo->lo_backing_file;

if (barrier) {
--
1.7.2.1


--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majordomo [at] vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Jiri Slaby [ Do, 12 August 2010 14:31 ] [ ID #2045907 ]

Re: [PATCH v2] BLOCK: fix bio.bi_rw handling

On Thu, Aug 12, 2010 at 02:31:06PM +0200, Jiri Slaby wrote:
> Return of the bi_rw tests is no longer bool after commit 74450be1. But
> results of such tests are stored in bools. This doesn't fit in there
> for some compilers (gcc 4.5 here), so either use !! magic to get real
> bools or use ulong where the result is assigned somewhere.

I'd have to look at my copy of the C standard if it's guaranteed, but
at least currently the values just get truncated down and bool still
is set to true. I'd much prefer just making these flags unsigned longs
instead of adding syntactic surage to make them true bools.

--
To unsubscribe from this list: send the line "unsubscribe linux-raid" in
the body of a message to majordomo [at] vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Christoph Hellwig [ Do, 12 August 2010 18:08 ] [ ID #2045927 ]

Re: [PATCH v2] BLOCK: fix bio.bi_rw handling

On 08/12/2010 06:08 PM, Christoph Hellwig wrote:
> On Thu, Aug 12, 2010 at 02:31:06PM +0200, Jiri Slaby wrote:
>> Return of the bi_rw tests is no longer bool after commit 74450be1. B=
ut
>> results of such tests are stored in bools. This doesn't fit in there
>> for some compilers (gcc 4.5 here), so either use !! magic to get rea=
l
>> bools or use ulong where the result is assigned somewhere.
>
> I'd have to look at my copy of the C standard if it's guaranteed,

=A76.5.3.3 of ANSI C99, par 5:
The result of the logical negation operator ! is 0 if the value of its
operand compares unequal to 0, 1 if the value of its operand compares
equal to 0. The result has type int. The expression !E is equivalent to
(0=3D=3DE).

On =3D=3D (=A76.5.9 par 3):
The =3D=3D (equal to) and !=3D (not equal to) operators are analogous t=
o the
relational operators except for their lower precedence. Each of the
operators yields 1 if the specified relation is true and 0 if it is
false. The result has type int. For any pair of operands, exactly one o=
f
the relations is true.

On bool =3D> _Bool (=A76.2.5 par 2)
An object declared as type _Bool is large enough to store the values 0
and 1.

So it should be safe :).

BTW just of curiosity, sizeof(bool) is 1 here (8 bits).

regards,
--
js
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" i=
n
the body of a message to majordomo [at] vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Jiri Slaby [ Do, 12 August 2010 18:24 ] [ ID #2045928 ]

Re: [PATCH v2] BLOCK: fix bio.bi_rw handling

On 2010-08-12 14:31, Jiri Slaby wrote:
> Return of the bi_rw tests is no longer bool after commit 74450be1. But
> results of such tests are stored in bools. This doesn't fit in there
> for some compilers (gcc 4.5 here), so either use !! magic to get real
> bools or use ulong where the result is assigned somewhere.

Added, sorry for the delay!

--
Jens Axboe

--
To unsubscribe from this list: send the line "unsubscribe linux-raid" in
the body of a message to majordomo [at] vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Jens Axboe [ Mo, 23 August 2010 12:33 ] [ ID #2046439 ]
Linux » gmane.linux.raid » [PATCH v2] BLOCK: fix bio.bi_rw handling

Vorheriges Thema: [BUG raid1] kernel BUG at drivers/scsi/scsi_lib.c:1113
Nächstes Thema: mdadm create problem with existing bitmap file